#ifndef COLLISION1D_CHARGEEXCHANGE_H
#define COLLISION1D_CHARGEEXCHANGE_H

#include <vector>

#include "../Tool/Macros.h"
#include "../Input/PicParams.h"
#include "../Species/Species.h"
#include "Collision1D.h"

class Collision1D_ChargeExchange : public Collision1D
{

public:

    Collision1D_ChargeExchange(PicParams* params_, CollisionParameter collision_param_, int collision_number_);

    ~Collision1D_ChargeExchange();

    void collide(PhysicalField* fields, vector<Species*>& vecSpecies, Diagnostic* diag, int itime);

    //get the maximum value of crossSection*velocity
    inline double max_cv(Species1D* s1, Species1D* s2)
    {
        double v_square;
        double v_magnitude;
        double ke;
        double maxCrossSectionV = 0.0;
        double crossSectionV;

        maxCrossSectionV = 0.0;
        for(int i_space = 0; i_space < params->dims_space[0]; i_space++)
        {
            auto cell_particles1 = s1->particles_[i_space];
            auto cell_particles2 = s2->particles_[i_space];

            int n_pair = cell_particles1->size();
            if(cell_particles2->size() < n_pair) { n_pair = cell_particles2->size(); }

            for(int i_pair = 0; i_pair < n_pair; i_pair++)
            {
                auto& p1 = cell_particles1->data_[i_pair];
                auto& p2 = cell_particles2->data_[i_pair];

                v_square = (p1.velocity[0] - p2.velocity[0]) * (p1.velocity[0] - p2.velocity[0]) +
                           (p1.velocity[1] - p2.velocity[1]) * (p1.velocity[1] - p2.velocity[1]) +
                           (p1.velocity[2] - p2.velocity[2]) * (p1.velocity[2] - p2.velocity[2]) ;
                v_magnitude = sqrt(v_square);

                //ke is energy (eV)
                ke = 0.5 * s1->species_param.mass * v_square / params->const_e;
                crossSectionV = v_magnitude * interplate_cross_section( ke );
                if(crossSectionV > maxCrossSectionV) { maxCrossSectionV = crossSectionV; }
            }

        }
        return maxCrossSectionV;
    };

    void calculate_scatter_velocity(Particle<1>& p1, Particle<1>& p2, double m1, double m2);

private:

    //the ionization threshold energy
    double energy_threshold;
};


#endif
